<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends Admin_Controller
{
	public function index()
	{
		show_404();	
	}
	
	public function change_password()
	{		
		$data['module'] = 'user';
		$data['page'] = 'layout_change_password';
		$this->load->view($this->layout_content,$data);	
	}
	
	public function action()
	{
		if( isset($_POST) )
		{
			$this->form_validation->set_rules('password_lama','Password lama','trim|required');
			$this->form_validation->set_rules('password_baru','Password baru','trim|required');	
			$this->form_validation->set_rules('konfirmasi_password','Konfirmasi password','trim|required|matches[password_baru]');
			
			if( $this->form_validation->run() === FALSE )
			{
				$error = error( validation_errors() );
				set_msg( $error );
				redirect( site_url('user/change_password') );	
				exit();
			}
			else
			{
				$old_password = $this->input->post('password_lama',true);
				$new_password = $this->input->post('password_baru',true);
				$change_password = $this->dx_auth->change_password($old_password,$new_password);
				
				if( !$change_password )
				{
					$error = error( $this->dx_auth->get_auth_error() );
					set_msg( $error );
					redirect( site_url('user/change_password') );	
					exit();
				}
				else
				{
					$msg = success("Password berhasil diubah");
					set_msg( $msg );
					redirect( site_url('user/change_password') );	
					exit();
				}
					
			}
		}	
	}
	
	public function check_password($str)
	{
			
	}
}